// Preferences.cs
//
//  Copyright (C) 2008-2009 Christian Eide
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// 
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
//

using System;
using System.Collections.Generic;

namespace Sarnata.Net.BareFtp.Preferences
{
	public class Config
	{
		private Dictionary<string, string> algorithms;
		
		public event EventHandler DefaultProtocolChanged;
		public event EventHandler ShowHiddenFilesChanged;
		
		public Config(string prefix)
		{
			algorithms = CreateAlgorithmDictionary();
		}
		
		public void WriteConfig()
		{
		}
		
        //protected void onConfigChanged(object sender, NotifyEventArgs args)
        //{
        //    if(DefaultProtocolChanged != null && args.Key == GCONF_APP_PATH + "/net/default_protocol")
        //    {
        //        DefaultProtocolChanged.Invoke(this, args);
        //    }
        //    else if(ShowHiddenFilesChanged != null && args.Key == GCONF_APP_PATH + "/general/show_hidden_files")
        //    {
        //        ShowHiddenFilesChanged.Invoke(this, args);
        //    }
			
        //}
		
		// TODO: This one has to go.. hack for ssh
		public string getSSHAlgorithm(string key)
		{
			if(algorithms != null)
			{
				if(algorithms.ContainsKey(key))
					return algorithms[key];
				else
					return null;
			}
			
			return null;
		}

        public string General_RemoteCharset
        {
            get { return string.Empty; }
        }
		
		public bool General_ShowHiddenFiles
		{
            get { return true; }
        }

		public bool General_PreserveFilePermissions
		{
            get { return false; }
        }
		
		public int GUI_VPanedPosition
		{
            get { return -1; }
        }
		
		public int GUI_HPanedPosition
		{
            get { return -1; }
        }
		
		public bool GUI_Maximized
		{
            get { return false; }
        }
		
		public string GUI_MessageFont
		{
            get { return "Monospace 8"; }
        }
		
		public string SSHKnownHostsFile
		{
            get { return System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), ".ssh/known_hosts");  }
        }
		
		public string SSHStrictKeyCheck
		{
            get { return "ask"; }
        }
		
		public string FTPSDataChannelProtectionLevel
		{
            get { return "C"; }
        }
		
		public bool FTP_PassiveMode
		{
            get { return true; }
        }
		
		public bool FTP_EmptyUserAnonymous
		{
            get { return true; }
        }
		
		public bool FTP_EmailAsAnonymousPass
		{
            get { return true; }
        }
		
		public string FTP_EmailAddress
		{
            get { return string.Format("{0}@{1}", Environment.UserName, Environment.UserDomainName); }
        }
		
		public int FTPDefaultPort
		{
			get { return 21; }
		}
		
		public int SSH_DefaultPort
		{
			get { return 22; }
		}
		
		public bool FTPSVerifyServerCertificate
		{
			get { return true; }
		}
		
		public int NetworkDefaultProtocol
		{
			get { return 1; }
		}
		
		public int NetworkTimeout
		{
			get { return 120000; }
		}
		
		private Dictionary<string,string> CreateAlgorithmDictionary()
		{
			Dictionary<string,string> tmp = new Dictionary<string,string>(); 
			tmp.Add("cipher.s2c", "3des-cbc,aes128-cbc");
			tmp.Add("cipher.c2s", "3des-cbc,aes128-cbc");
			tmp.Add("mac.s2c", "hmac-md5,hmac-sha1");
			tmp.Add("mac.c2s", "hmac-md5,hmac-sha1");
			tmp.Add("compression.s2c", "none");
			tmp.Add("compression.c2s", "none");
			tmp.Add("lang.s2c", string.Empty);
			tmp.Add("lang.c2s", string.Empty);
			tmp.Add("diffie-hellman-group-exchange-sha1", "bareFTP.Protocol.Sftp.DHGEX");
			tmp.Add("diffie-hellman-group1-sha1", "bareFTP.Protocol.Sftp.DHG1");
			tmp.Add("dh", "bareFTP.Protocol.Sftp.jce.DH");
			tmp.Add("3des-cbc", "bareFTP.Protocol.Sftp.jce.TripleDESCBC");
			tmp.Add("hmac-sha1", "bareFTP.Protocol.Sftp.jce.HMACSHA1");
			tmp.Add("hmac-sha1-96", "bareFTP.Protocol.Sftp.jce.HMACSHA196");
			tmp.Add("hmac-md5", "bareFTP.Protocol.Sftp.jce.HMACMD5");
			tmp.Add("hmac-md5-96", "bareFTP.Protocol.Sftp.jce.HMACMD596");
			tmp.Add("sha-1", "bareFTP.Protocol.Sftp.jce.SHA1");
			tmp.Add("md5", "bareFTP.Protocol.Sftp.jce.MD5");
			tmp.Add("signature.dss", "bareFTP.Protocol.Sftp.jce.SignatureDSA");
			tmp.Add("signature.rsa", "bareFTP.Protocol.Sftp.jce.SignatureRSA");
			tmp.Add("keypairgen.dsa", "bareFTP.Protocol.Sftp.jce.KeyPairGenDSA");
			tmp.Add("keypairgen.rsa", "bareFTP.Protocol.Sftp.jce.KeyPairGenRSA");
			tmp.Add("aes128-cbc", "bareFTP.Protocol.Sftp.jce.AES128CBC");
			tmp.Add("kex", "diffie-hellman-group1-sha1,diffie-hellman-group-exchange-sha1");
			tmp.Add("server_host_key", "ssh-rsa,ssh-dss");
			return tmp;
		}
	}
}
